#!/usr/bin/expect -f
# 设置ssh连接的用户名
set user root
# 设置ssh连接的host地址
set host 192.168.11.19
# 设置ssh连接的登录密码
set password cgm123

#项目路径
set projectPath /home/lwyfront/

#项目名称
set projectName lwyapi

set tmpProjectName lwyapitmp


#将本地压缩包拷贝的远端
spawn scp /home/yu/code/yungengxin2019/lwyapi/lwyapi $user@$host:$projectPath
expect "*password:"
send "$password\r"

spawn scp -r /home/yu/code/yungengxin2019/lwyapi/confenv $user@$host:${projectPath}
expect "*password:"
send "$password\r"


#登录远端
spawn ssh $user@$host
expect "*password:"
send "$password\r"


#进入远端项目目录
expect "]*"
send "cd $projectPath && rm -f lwyfront && mv lwyapi lwyfront  && chmod +x lwyfront\r"

sleep 2

#重启
expect "]*"
send "./kill.sh \r"


#退出
expect "]*"
send "nohup ./lwyfront >>lwyfront.log 2>>run.log & \r"

expect "]*"
send "head -n 3 run.log \r"

expect "]*"
send "exit\r"

# 控制权移交
interact